/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Ownership")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ownership.findAll", query = "SELECT o FROM Ownership o"),
    @NamedQuery(name = "Ownership.findByPlayer", query = "SELECT o FROM Ownership o WHERE o.ownershipPK.player = :player"),
    @NamedQuery(name = "Ownership.findByConstruct", query = "SELECT o FROM Ownership o WHERE o.ownershipPK.construct = :construct"),
    @NamedQuery(name = "Ownership.findByAmount", query = "SELECT o FROM Ownership o WHERE o.amount = :amount"),
    @NamedQuery(name = "Ownership.findByOccupied", query = "SELECT o FROM Ownership o WHERE o.occupied = :occupied")})
public class Ownership implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected OwnershipPK ownershipPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "amount")
    private int amount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "occupied")
    private int occupied;
    @Basic(optional = false)
    @NotNull
    @Column(name = "uncomplited")
    private int uncomplited;
    @JoinColumn(name = "construct", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Construct construct1;
    @JoinColumn(name = "player", referencedColumnName = "username", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Player player1;

    public Ownership() {
    }

    public Ownership(OwnershipPK ownershipPK) {
        this.ownershipPK = ownershipPK;
    }

    public Ownership(OwnershipPK ownershipPK, int amount, int occupied) {
        this.ownershipPK = ownershipPK;
        this.amount = amount;
        this.occupied = occupied;
    }

    public Ownership(String player, String construct) {
        this.ownershipPK = new OwnershipPK(player, construct);
    }

    public OwnershipPK getOwnershipPK() {
        return ownershipPK;
    }

    public void setOwnershipPK(OwnershipPK ownershipPK) {
        this.ownershipPK = ownershipPK;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public int getOccupied() {
        return occupied;
    }

    public void setOccupied(int occupied) {
        this.occupied = occupied;
    }

    public int getUncomplited() {
        return uncomplited;
    }

    public void setUncomplited(int uncomplited) {
        this.uncomplited = uncomplited;
    }

    public Construct getConstruct1() {
        return construct1;
    }

    public void setConstruct1(Construct construct1) {
        this.construct1 = construct1;
    }

    public Player getPlayer1() {
        return player1;
    }

    public void setPlayer1(Player player1) {
        this.player1 = player1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ownershipPK != null ? ownershipPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ownership)) {
            return false;
        }
        Ownership other = (Ownership) object;
        if ((this.ownershipPK == null && other.ownershipPK != null) || (this.ownershipPK != null && !this.ownershipPK.equals(other.ownershipPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Ownership[ ownershipPK=" + ownershipPK + " ]";
    }
}
